package com.tian.print.utils;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class Utils {


    /**
     * 获取屏幕的宽度
     *
     * @param context 上下文
     * @return 屏幕的宽度
     */
    public static int getWindowWidth(Context context) {
        WindowManager wm = (WindowManager) (context
                .getSystemService(Context.WINDOW_SERVICE));
        DisplayMetrics dm = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(dm);
        return dm.widthPixels;
    }


    /**
     * 获取屏幕的高度
     *
     * @param context 上下文
     * @return 屏幕的宽度
     */
    public static int getWindowHeigh(Context context) {
        WindowManager wm = (WindowManager) (context
                .getSystemService(Context.WINDOW_SERVICE));
        DisplayMetrics dm = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(dm);
        return dm.heightPixels;
    }

    /**
     * 将String 变成toRequestBody
     *
     * @param value
     * @return
     */
    public static RequestBody toRequestBody(String value) {
        RequestBody requestBody = RequestBody.create(MediaType.parse("text/plain"), value);
        return requestBody;
    }
    /**
     * 将String 变成toRequestBody
     *
     * @param value
     * @return
     */
    public static RequestBody toRequestBodyJSON(String value) {
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), value);
        return requestBody;
    }


}
